﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace Spider.Dual_coloredBall
{
    /// <summary>
    /// 类GameResultsDetail。
    /// </summary>
    [Serializable]
    public partial class GameResultsDetail
    {
        public GameResultsDetail()
        { }
        #region Model
        private int _id;
        private string _gamenum;
        private string _prizename;
        private string _condition;
        private int? _samenum = 0;
        private decimal? _moneyaward = 0M;
        /// <summary>
        /// 
        /// </summary>
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string GameNum
        {
            set { _gamenum = value; }
            get { return _gamenum; }
        }
        /// <summary>
        /// 奖项
        /// </summary>
        public string PrizeName
        {
            set { _prizename = value; }
            get { return _prizename; }
        }
        /// <summary>
        /// 中奖条件
        /// </summary>
        public string Condition
        {
            set { _condition = value; }
            get { return _condition; }
        }
        /// <summary>
        /// 中奖注数
        /// </summary>
        public int? SameNum
        {
            set { _samenum = value; }
            get { return _samenum; }
        }
        /// <summary>
        /// 单注奖金
        /// </summary>
        public decimal? MoneyAward
        {
            set { _moneyaward = value; }
            get { return _moneyaward; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public GameResultsDetail(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,GameNum,PrizeName,Condition,SameNum,MoneyAward ");
            strSql.Append(" FROM [GameResultsDetail] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameNum"] != null)
                {
                    this.GameNum = ds.Tables[0].Rows[0]["GameNum"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PrizeName"] != null)
                {
                    this.PrizeName = ds.Tables[0].Rows[0]["PrizeName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Condition"] != null)
                {
                    this.Condition = ds.Tables[0].Rows[0]["Condition"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SameNum"] != null && ds.Tables[0].Rows[0]["SameNum"].ToString() != "")
                {
                    this.SameNum = int.Parse(ds.Tables[0].Rows[0]["SameNum"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MoneyAward"] != null && ds.Tables[0].Rows[0]["MoneyAward"].ToString() != "")
                {
                    this.MoneyAward = decimal.Parse(ds.Tables[0].Rows[0]["MoneyAward"].ToString());
                }
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [GameResultsDetail]");
            strSql.Append(" where ID=@ID ");

            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            return DbHelperOleDb.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [GameResultsDetail] (");
            strSql.Append("GameNum,PrizeName,Condition,SameNum,MoneyAward)");
            strSql.Append(" values (");
            strSql.Append("@GameNum,@PrizeName,@Condition,@SameNum,@MoneyAward)");
            OleDbParameter[] parameters = {
					new OleDbParameter("@GameNum", OleDbType.VarChar,255),
					new OleDbParameter("@PrizeName", OleDbType.VarChar,255),
					new OleDbParameter("@Condition", OleDbType.VarChar,255),
					new OleDbParameter("@SameNum", OleDbType.Integer,4),
					new OleDbParameter("@MoneyAward", OleDbType.Decimal)};
            parameters[0].Value = GameNum;
            parameters[1].Value = PrizeName;
            parameters[2].Value = Condition;
            parameters[3].Value = SameNum;
            parameters[4].Value = MoneyAward;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [GameResultsDetail] set ");
            strSql.Append("GameNum=@GameNum,");
            strSql.Append("PrizeName=@PrizeName,");
            strSql.Append("Condition=@Condition,");
            strSql.Append("SameNum=@SameNum,");
            strSql.Append("MoneyAward=@MoneyAward");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@GameNum", OleDbType.VarChar,255),
					new OleDbParameter("@PrizeName", OleDbType.VarChar,255),
					new OleDbParameter("@Condition", OleDbType.VarChar,255),
					new OleDbParameter("@SameNum", OleDbType.Integer,4),
					new OleDbParameter("@MoneyAward", OleDbType.Decimal),
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = GameNum;
            parameters[1].Value = PrizeName;
            parameters[2].Value = Condition;
            parameters[3].Value = SameNum;
            parameters[4].Value = MoneyAward;
            parameters[5].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [GameResultsDetail] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,GameNum,PrizeName,Condition,SameNum,MoneyAward ");
            strSql.Append(" FROM [GameResultsDetail] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GameNum"] != null)
                {
                    this.GameNum = ds.Tables[0].Rows[0]["GameNum"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PrizeName"] != null)
                {
                    this.PrizeName = ds.Tables[0].Rows[0]["PrizeName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Condition"] != null)
                {
                    this.Condition = ds.Tables[0].Rows[0]["Condition"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SameNum"] != null && ds.Tables[0].Rows[0]["SameNum"].ToString() != "")
                {
                    this.SameNum = int.Parse(ds.Tables[0].Rows[0]["SameNum"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MoneyAward"] != null && ds.Tables[0].Rows[0]["MoneyAward"].ToString() != "")
                {
                    this.MoneyAward = decimal.Parse(ds.Tables[0].Rows[0]["MoneyAward"].ToString());
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [GameResultsDetail] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

